package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.Scene;
import com.example.service.SceneService;
import com.example.mapper.SceneMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author luo20
 * @description 针对表【scene(场景表)】的数据库操作Service实现
 * @createDate 2025-06-23 10:13:28
 */
@Service
public class SceneServiceImpl extends ServiceImpl<SceneMapper, Scene>
        implements SceneService {

    @Autowired
    private SceneMapper sceneMapper;

    @Override
    public Integer createScene(Scene scene) {
        return sceneMapper.insert(scene);
    }

    @Override
    public List<Scene> getScenes(Long creatorId) {
        LambdaQueryWrapper<Scene> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Scene::getCreatorId, creatorId);
        return sceneMapper.selectList(queryWrapper);
    }

    @Override
    public boolean executeScene(Long sceneId) {
        Scene scene = sceneMapper.selectById(sceneId);
        if (scene != null) {
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteScene(Long sceneId) {
        return sceneMapper.deleteById(sceneId) > 0;
    }

}
